package com.totcy.baselibrary.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.totcy.baselibrary.base.mvpbase.BasePresenterImpl;
import com.totcy.baselibrary.base.mvpbase.BaseView;
import com.totcy.baselibrary.utils.TUtil;


/**
 * Description 封装mvp的基类activity
 *
 * @author: tu
 * Date: 2016-12-02
 * Time: 16:40
 */
public abstract class BaseMvpActivity<V extends BaseView, P extends BasePresenterImpl> extends BaseActivity implements BaseView {

    private P mPresenter;

    public P getPresenter() {
        return mPresenter;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        //提前初始化presenter
        initWidget();
        super.onCreate(savedInstanceState);
    }

    /**
     * 初始化mvp
     */
    private void initWidget() {
        mPresenter = TUtil.getPresenterT(this, this, 1);
        //实现view
        if (mPresenter != null) {
            mPresenter.attachView((V) this);
        }
    }

    /**
     * 显示加载框
     */
    @Override
    public void showProgress(String message) {
    }

    /**
     * 隐藏加载框
     */
    @Override
    public void dismissProgress() {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
            mPresenter.detachModel();
        }
    }
}
